import codesecurity.feature.node_type_const as nodeTypeConst
import codesecurity.feature.objects as featureObj

import numpy as np

def count_node_type_js(ast_object:featureObj.Ast):
    
    node_types=nodeTypeConst.JSNodeTypes()
    
    vector_dim=len(node_types.list_names())
    index_mapping={node_type:i for i,node_type in enumerate(node_types.list_names())}
    
    count_vector=np.zeros(vector_dim)
    
    
    for node in ast_object.nodes:
        node_type=node.ast_type
        if node_type in index_mapping:
            count_vector[index_mapping[node_type]]+=1
    
    return count_vector